package org.firebug.spring.boot.swagger.api.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.firebug.common.core.api.Pagination;
import org.firebug.common.core.api.Response;
import org.firebug.spring.boot.swagger.api.dto.UserDTO;
import org.firebug.spring.boot.swagger.api.qo.UserQO;
import org.firebug.spring.boot.swagger.api.vo.UserVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping(value = "/user")
@Api(tags = {"/user"}, description = "用户")
public class UserController {
    /**
     * Content-Type = application/x-www-form-urlencoded
     * Content-Type = multipart/form-data
     * Content-Type = application/json; charset=UTF-8
     */

    /**
     * Content-Type = application/json; charset=UTF-8
     * RequestMethod = POST
     */
    @ApiOperation(value = "保存", notes = "保存详细说明", tags = {"1.0"})
    @RequestMapping(value = "/save", method = RequestMethod.POST, params = {"version=1"})
    public Response<Void> save(@Validated(UserDTO.Save.class) @RequestBody UserDTO dto) {
        return Response.ok();
    }

    /**
     * Content-Type = application/json; charset=UTF-8
     * RequestMethod = PUT
     */
    @ApiOperation(value = "修改", notes = "修改详细说明", tags = {"1.0"})
    @RequestMapping(value = "/modify", method = RequestMethod.PUT, params = {"version=1"})
    public Response<Void> modify(@Validated(UserDTO.Modify.class) @RequestBody UserDTO dto) {
        return Response.ok();
    }

    /**
     * Content-Type = application/x-www-form-urlencoded
     * RequestMethod = DELETE
     */
    @ApiOperation(value = "删除", notes = "删除详细说明", tags = {"1.1"})
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.DELETE, params = {"version=1"})
    public Response<Void> deleteByPath(@PathVariable Long id) {
        return Response.ok();
    }

    /**
     * Content-Type = application/x-www-form-urlencoded
     * RequestMethod = DELETE
     */
    @ApiOperation(value = "删除", notes = "删除详细说明", tags = {"1.1"})
    @RequestMapping(value = "/delete", method = RequestMethod.DELETE, params = {"version=1"})
    public Response<Void> deleteByParam(@RequestParam Long id) {
        return Response.ok();
    }

    /**
     * Content-Type = application/x-www-form-urlencoded
     * RequestMethod = GET
     */
    @ApiOperation(value = "查询", notes = "查询详细说明", tags = {"1.2"})
    @RequestMapping(value = "/query/{id}", method = RequestMethod.GET, params = {"version=1"})
    public Response queryByPath(@PathVariable Long id) {
        return Response.ok(new UserVO());
    }

    /**
     * Content-Type = application/x-www-form-urlencoded
     * RequestMethod = GET
     */
    @ApiOperation(value = "查询", notes = "查询详细说明", tags = {"1.2"})
    @RequestMapping(value = "/query", method = RequestMethod.GET, params = {"version=1"})
    public Response<UserVO> queryByParam(@RequestParam Long id) {
        return Response.ok(new UserVO());
    }

    /**
     * Content-Type = application/x-www-form-urlencoded
     * RequestMethod = GET
     */
    @ApiOperation(value = "列表", notes = "列表详细说明", tags = {"1.2"})
    @RequestMapping(value = "/list-by-param", method = RequestMethod.GET, params = {"version=1"})
    @ApiImplicitParams({
//        注：需要name, dateType
        @ApiImplicitParam(name="page", value="页码", required = true, dataType = "int", example = "1"),
        @ApiImplicitParam(name="size", value="页长", required = true, dataType = "int", example = "10")
    })
    public Response<List<UserVO>> listByParam(@RequestParam Integer page, @RequestParam Integer size) {
        return Response.ok(Arrays.asList(new UserVO()), new Pagination(page, size, 1));
    }

    /**
     * Content-Type = application/x-www-form-urlencoded
     * RequestMethod = GET
     */
    @ApiOperation(value = "列表", notes = "列表详细说明", tags = {"1.2"})
    @RequestMapping(value = "/list-by-model", method = RequestMethod.GET, params = {"version=1"})
    public Response<List<UserVO>> listByModel(@Validated UserQO qo) {
        return Response.ok(Arrays.asList(new UserVO()), new Pagination(qo.getPage(), qo.getSize(), 1));
    }
}

